from openpyxl import load_workbook
import requests
import time

ID = "ww7b4086d88a144eec"
SECRET = "Yy-hdts7KZHFDO8tzwWTNUfPiGyssUOo8XAPz2IOnbA"
url_get_access_token = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + ID + "&corpsecret=" + SECRET

#获取access_token#
def get_access_token(ID,SECRET):
    access_token_json = requests.get(url_get_access_token).json()
    while access_token_json['errcode'] != 0:
        get_access_token(ID, SECRET)
        time.sleep(2)
    access_token = access_token_json['access_token']
    return access_token


def get_member_name_department(filename):
    userid_list = load_workbook(filename).worksheets[0]['E']
    for userid in userid_list[1:len(userid_list)-1]:
        print(userid.value)
        url_get_member_detail = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=" + get_access_token(ID, SECRET) + "&userid=" + eval(userid)
    return
get_member_name_department('D:\推送（客户）18095208.xlsx')